package com.cloudxingkong.dianyinke.Student.Adapter;
import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.cloudxingkong.dianyinke.R;
import com.cloudxingkong.dianyinke.Student.bean.QbfkEntity;
import com.nostra13.universalimageloader.core.ImageLoader;

import java.util.List;

/**
 * Created by ningfei on 2016/3/30.
 */
public class QbfkAdapter extends BaseAdapter{
    private List<QbfkEntity.ListBean> data;
    private Context context;
    private onTouchPos onTouchPos;


    public QbfkAdapter(List<QbfkEntity.ListBean> data, Context context,onTouchPos onTouchPos) {
        this.data = data;
        this.context = context;
        this.onTouchPos = onTouchPos;

    }

    @Override

    public int getCount() {
        return data == null ? 0 : data.size();
    }

    @Override
    public Object getItem(int position) {
        return data == null ? null : data.get(position);
    }

    @Override
    public long getItemId(int position) {
        return  position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder = null;
        if (convertView==null){
            convertView = View.inflate(context, R.layout.qbfk_item,null);
            holder = new ViewHolder();
            holder.tv_qbfk_type = (TextView) convertView.findViewById(R.id.tv_qbfk_type);
            holder.tv_qbfk_title = (TextView) convertView.findViewById(R.id.tv_qbfk_title);
            holder.tv_qbfk_guige = (TextView) convertView.findViewById(R.id.tv_qbfk_guige);
            holder.tv_qbfk_jifen = (TextView) convertView.findViewById(R.id.tv_qbfk_jifen);
            holder.tv_qbfk_shifukuan = (TextView) convertView.findViewById(R.id.tv_qbfk_shifukuan);
            holder.tv_qbfk_zhifu = (TextView) convertView.findViewById(R.id.tv_qbfk_zhifu);
            holder.iv_qbfk_qianbi = ((ImageView) convertView.findViewById(R.id.iv_qbfk_qianbi));

            holder.ll_qbfk_daifukuan = ((LinearLayout) convertView.findViewById(R.id.ll_daifukuan));
            holder.ll_qbfk_daifahuo = ((LinearLayout) convertView.findViewById(R.id.ll_daifahuo));
            holder.ll_qbfk_daishouhuo = ((LinearLayout) convertView.findViewById(R.id.ll_daishouhuo));
            holder.ll_qbfk_daipingjia = ((LinearLayout) convertView.findViewById(R.id.ll_daipingjia));
            holder.tv_qbfk_abc = ((TextView) convertView.findViewById(R.id.tv_qbfk_abc));//item红色type

            convertView.setTag(holder);
        }else {
            holder = (ViewHolder) convertView.getTag();
        }
        onTouchPos.onTouch(position);
        holder.tv_qbfk_type.setText(data.get(position).getName()+"");//名称
        holder.tv_qbfk_title.setText(data.get(position).getNote()+"");//标题
        holder.tv_qbfk_guige.setText(data.get(position).getSize()+"");//规格
        holder.tv_qbfk_jifen.setText(data.get(position).getTotalpoints() + "");//使用积分
        holder.tv_qbfk_shifukuan.setText(data.get(position).getMoney() + "");//实付款
        String pic = data.get(position).getPic()+"";
        ImageLoader.getInstance().displayImage(pic, holder.iv_qbfk_qianbi);
        int status = data.get(position).getStatus();
         if (status==1) {
             holder.tv_qbfk_abc.setText("待付款");
             holder.ll_qbfk_daifukuan.setVisibility(View.VISIBLE);
             holder.ll_qbfk_daifahuo.setVisibility(View.GONE);
             holder.ll_qbfk_daipingjia.setVisibility(View.GONE);
             holder.ll_qbfk_daishouhuo.setVisibility(View.GONE);


         }else if (status==2) {
             holder.tv_qbfk_abc.setText("待发货");
             holder.ll_qbfk_daifahuo.setVisibility(View.VISIBLE);
             holder.ll_qbfk_daifukuan.setVisibility(View.GONE);
             holder.ll_qbfk_daipingjia.setVisibility(View.GONE);
             holder.ll_qbfk_daishouhuo.setVisibility(View.GONE);
         }else  if (status==3) {
             holder.tv_qbfk_abc.setText("待收货");
             holder.ll_qbfk_daishouhuo.setVisibility(View.VISIBLE);
             holder.ll_qbfk_daifukuan.setVisibility(View.GONE);
             holder.ll_qbfk_daipingjia.setVisibility(View.GONE);
             holder.ll_qbfk_daifahuo.setVisibility(View.GONE);
         }else   if (status==4){
             holder.tv_qbfk_abc.setText("待评价");
             holder.ll_qbfk_daipingjia.setVisibility(View.VISIBLE);
             holder.ll_qbfk_daifukuan.setVisibility(View.GONE);
             holder.ll_qbfk_daifahuo.setVisibility(View.GONE);
             holder.ll_qbfk_daishouhuo.setVisibility(View.GONE);
         }



        return convertView;
    }
    private class ViewHolder{
        private TextView tv_qbfk_type,tv_qbfk_title,tv_qbfk_guige,tv_qbfk_jifen,tv_qbfk_shifukuan,tv_qbfk_quxiaodingdan,tv_qbfk_zhifu;
        private ImageView iv_qbfk_qianbi;
        private LinearLayout ll_qbfk_daifukuan,ll_qbfk_daifahuo,ll_qbfk_daishouhuo,ll_qbfk_daipingjia;
        private TextView tv_qbfk_abc;
    }
    //接口回调
    public  interface onTouchPos{
        public void onTouch(int position);
    }
}
